<% 
    var headContent = {
  %>
  <style type="text/css">
  .tr-selected {
    background-color: #fcb287;
    border: 1px solid #fcb287;
  </style>
  <script type="text/javascript">

      //多选框全选支持代码
      $(function() {
          selectAll('#city_org_select');
      });
      var getCityOrgVal = function(){
          var city_org_ids = $("#city_org_select").val();
          $("#city_org_ids").val(city_org_ids);
          var $selected = $('#city_org_select');
      }
      var cityOrgAllSelect = function(){
          alert("come");
          var city_org_ids = $("#city_org_select").val();
          if(city_org_ids.indexOf("-1")!=-1){
              console.log("all select ---------");
          }else{
              console.log("no select ---------");
          }
          console.log("do something select ---------");
      }




   $(function(){




      $("body").on('click', '.list-item', function() {
       $(".list-item").removeClass("tr-selected");
       $(this).addClass('tr-selected');
      });
      $("body").on('click', '#searchBtn', function() {
      
        var keywords = {
           keyword:$("#keyword").val(),
           queryType:$("#queryType").val()
        }
        document.location.href="${base}/spreadMemberAuthConfig/dialogChannelBusiness?type=${type}&keywords="+JSON.stringify(keywords);
      });
       //当本页面属于其他页面的弹出页面时
       if (frameElement != null && frameElement.api != null) {
        var api = frameElement.api;
        api.button({
          id: 'valueOk',
          name: '确定',
          focus: true,
          callback: function () {
            var selectItems = $(".tr-selected");
            if (selectItems.length < 1) {
              alert("您没有选择任何数据！");
              return false;
            } else {
              //W = api.opener;
              //var parant = W.document.getElementById("callback");//调用父窗体元素
              var backdata = [];
             for (var i = 0; i < selectItems.length; i++) {
              var tr= selectItems[i];
              var channel = {};
              channel.id=$(tr).data("id");
              channel.class_name=$(tr).data("class_name");
              channel.websiteId=$(tr).data("website_id");
              channel.cityOrgIds = $("#city_org_ids").val();
              backdata.push(channel);
             };
             console.info(backdata);
              if (api.data != 'undefined') {
                api.data(backdata);
              }
              return true;
            }
          }
        }, { id: 'valueCancel', name: '取消' });
      }            
   });
   </script>
  <%
};
%>
<%layout("/common/_layout.html",{head:headContent}){ %>
  <%#ajax userTable:{%>
  <div class="am-g">
     <div class="am-u-sm-6">&nbsp; </div>
     <div class="am-u-sm-3">
       <select id="queryType" name="queryType" data-am-selected="{btnSize: 'sm'}">
         <option <%if (isEmpty(queryType)||queryType=="fuzzy"){%>
                     selected = "selected"
                  <%}%> value="fuzzy">模糊查询</option>
         <option <%if (!isEmpty(queryType) && queryType=="exact"){%>
                     selected = "selected"
                  <%}%> value="exact">精确查询</option>
       </select>
     </div>
     <div class="am-u-sm-3">
       <div class="am-input-group am-input-group-sm">        
         <input type="text" class="am-form-field" id="keyword" placeholder="渠道编码或名称" value="${keyword!}">
         <span class="am-input-group-btn">
           <button class="am-btn am-btn-default" type="button" id="searchBtn" >搜索</button>
         </span>
       </div>
     </div>
   </div>




<div class="am-g" style="margin-top: 3rem;margin-bottom: 3rem;">

    <div  class="am-u-sm-12">
        <div class="am-u-sm-8 am-u-md-8">
            <input type="hidden" value="" id="city_org_ids" name="city_org_ids"/>
            <select  onchange="getCityOrgVal()"
                     multiple data-am-selected="{btnWidth:'100%',maxHeight:300,maxWidth:200,searchBox: 1,placeholder:'选择地市'}" id="city_org_select" name="city_org_select">
                <option id="allSelectOp"  value="-1" onclick="cityOrgAllSelect()">全选</option>
                <%for(cityOrg in cityList){%>
                <option  value="${cityOrg.id}" >${cityOrg.DisplayName}</option>
                <%}%>
            </select>
        </div>

    </div>
</div>






   <div class="am-g">
     <div class="am-u-sm-12">
         <table class="am-table table-main">
             <thead>
                 <tr>
                     <th>渠道ID</th>
                     <th>渠道编码</th>
                     <th>渠道名称</th>
                 </tr>
             </thead>
          <tbody>
             <%for(list in pager.list!){%>
                <tr class="list-item" data-id="${list.id}" data-class_name="${list.class_name}" data-website_id="${list.WebsiteId}">
                 <td>${list.id!}</td>
                 <td>${list.WebsiteId!}</td>
                 <td>${list.class_name!}</td>
               </tr>
             <%}%> 
          </tbody>
       </table>
        <div class="am-cf">
           <!-- 分页 -->
           <%if (pager.list.~size > 0){%>
               <div class="am-fr">
                   <% include("/admin/business_auth_config_dialog_pager.tpl"){}%>
               </div>
           <%}else{%>
               <div class="am-kai" style="min-height: 50rem;">
                 <h3>没有找到任何记录!</h3>
               </div>
           <%}%>
        </div>
       <%}%>
     </div>
   </div>
   
<%}%>
